Don't average coords to center map. Instead use bounding box.
authorrobertl <robertl@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Tue, 2 Sep 2003 16:53:10 +0000 (16:53 +0000)
committerrobertl <robertl@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Tue, 2 Sep 2003 16:53:10 +0000 (16:53 +0000)
gpsbabel/tiger.c

index 2ac41f3c83e6e3806f641e60b76f9332fc5b0eb7..3233202e8dbd78d7c6c2ae787425e118148b8c58 100644 (file)
@@ -143,9 +143,6 @@ tiger_disp(const waypoint *wpt)
                if (lon > maxlon) maxlon = lon;
                if (lat < minlat) minlat = lat;
                if (lon < minlon) minlon = lon;
-               latsum += lat;
-               lonsum += lon;
-               rec_cnt++;
        }
 
        fprintf(file_out, "%f,%f:%s", lon, lat, pin);
@@ -179,6 +176,7 @@ data_write(void)
        minlat = 9999.0;
        minlon = 9999.0;
        rec_cnt = 0;
+       double latsz,lonsz;
 
        if (snlen)
                short_length = atoi(snlen);
@@ -198,12 +196,23 @@ data_write(void)
                        fatal(MYNAME ": Cannot open '%s' for writing\n", 
                                        genurl);
                } 
-
+               latsz = fabs(maxlat - minlat); 
+               lonsz = fabs(maxlon - minlon); 
+
+               /*
+                * Center the map along X and Y axis the midpoint of
+                * our min and max coords each way.   Size it with an 
+                * additional little boundary becuase Tiger always puts
+                * the pin above the actual coord and if we don't pad
+                * the top will be clipped.   It also makes the maps 
+                * more useful to have a little bit of context around
+                * the pins on the border.
+                */
                fprintf(urlf, "lat=%f&lon=%f&wid=%f&ht=%f",
-                               latsum / rec_cnt,
-                               lonsum / rec_cnt,
-                               maxlat - minlat,
-                               maxlon - minlon);
+                               minlat + (latsz/2.0),
+                               minlon + (lonsz/2.0),
+                               latsz * 1.15,
+                               latsz * 1.15);
 
                if (scale) {
                        fprintf(urlf, "&iwd=%s&iht=%s", scale, scale);